import dayjs from "dayjs";

const concernedTags0213 = [
  "ZUUU_DEP_BOKIR",
  "ZUUU_DEP_GURET",
  "ZUUU_DEP_UBRAB",
  "ZUUU_ARR_MEXAD",
  "ZUUU_ARR_AKDIK",
  "ZUTF_DEP_BOKIR",
  "ZUTF_DEP_SAGPI",
  "ZUTF_DEP_UBRAB",
  "ZUTF_DEP_MUMGO",
  "ZUTF_ARR_MEXAD",
  "ZUMY_DEP_BOKIR",
  "ZUMY_DEP_SAGPI",
  "ZUMY_DEP_UBRAB",
  "ZUMY_DEP_JTG",
  "ZUMY_ARR_MEXAD",
  "ZUMY_ARR_AKDIK",
  "ZUMY_ARR_BUPMI",
  "ZUMY_ARR_IGNAK",
  "ZUMY_ARR_LADUP",
  "ZUYB_ARR_UBKER",
  "ZULZ_ARR_UBKER",
];

const concernedTags0203 = [
  "ZUUU_ARR_MEXAD",
  "ZUUU_ARR_AKDIK",
  "ZUTF_ARR_MEXAD",
  "ZUTF_ARR_BUPMI",
  "ZUMY_ARR_MEXAD",
  "ZUMY_ARR_AKIDK",
  "ZUMY_ARR_BUPMI",
  "ZUMY_ARR_LADUP",
  "ZUMY_ARR_IGNAK",
  "ZUMY_DEP_BOKIR",
  "ZUMY_DEP_SAGPI",
  "ZUMY_DEP_UBRAB",
  "ZUMY_DEP_JTG",
];

const concernedTags0313 = [
  "ZUUU_DEP_BOKIR",
  "ZUUU_DEP_GURET",
  "ZUUU_DEP_UBRAB",
  "ZUTF_DEP_BOKIR",
  "ZUTF_DEP_SAGPI",
  "ZUTF_DEP_UBRAB",
  "ZUTF_DEP_MUMGO",
  "ZUTF_ARR_MEXAD",
  "ZUTF_ARR_BUPMI",
  "ZUMY_ARR_BUPMI",
  "ZUMY_DEP_SAGPI",
  "ZUMY_DEP_UBRAB",
  "ZUYB_ARR_UBKER",
  "ZULZ_ARR_UBKER",
];

const concernedTags020313 = [
  "ZUUU_DEP_BOKIR",
  "ZUUU_DEP_GURET",
  "ZUUU_DEP_UBRAB",
  "ZUUU_ARR_MEXAD",
  "ZUUU_ARR_AKDIK",
  "ZUTF_DEP_BOKIR",
  "ZUTF_DEP_SAGPI",
  "ZUTF_DEP_UBRAB",
  "ZUTF_DEP_MUMGO",
  "ZUTF_ARR_MEXAD",
  "ZUTF_ARR_BUPMI",
  "ZUMY_DEP_BOKIR",
  "ZUMY_DEP_SAGPI",
  "ZUMY_DEP_UBRAB",
  "ZUMY_DEP_JTG",
  "ZUMY_ARR_MEXAD",
  "ZUMY_ARR_AKDIK",
  "ZUMY_ARR_BUPMI",
  "ZUMY_ARR_IGNAK",
  "ZUMY_ARR_LADUP",
  "ZUYB_ARR_UBKER",
  "ZULZ_ARR_UBKER",
];

export default function ({
  tags,
  rawData,
  begTime,
  opMode,
  tagGroup = "0203",
}) {
  let concernedTags = concernedTags0213;
  if (tagGroup == "0203") {
    concernedTags = concernedTags0203;
  } else if (tagGroup == "0313") {
    concernedTags = concernedTags0313;
  } else if (tagGroup == "0213") {
    concernedTags = concernedTags0213;
  } else if (tagGroup == "020313") {
    concernedTags = concernedTags020313;
  }
  console.log("chart213", concernedTags);
  let idxList = [];
  for (let i = 0; i < tags.length; i++) {
    if (concernedTags.includes(tags[i])) {
      idxList.push(i);
    }
  }

  let taggedData = [];
  for (let i = 0; i < rawData.length; i += 2) {
    if (i == rawData.length - 1) {
      break;
    }
    let day = dayjs(begTime).add(i * 15, "minute");
    let details = {};
    let valArr = 0;
    let valDep = 0;
    let valAll = 0;
    // start of appendings @20240826
    // about ZUMY
    let valDepMainMY = 0;
    let valDepMiscMY = 0;
    let valArrMY = 0;
    // about ZUUU & ZUTF
    // ???
    // about flypass
    let valPass = 0;
    // end of appendings @20240826
    idxList.forEach((tagIdx) => {
      let val = rawData[i][tagIdx] + rawData[i + 1][tagIdx];
      details[tags[tagIdx]] = val;
      valAll += val;
      if (
        tags[tagIdx].includes("ZUUU_ARR") ||
        tags[tagIdx].includes("ZUTF_ARR")
      ) {
        valArr += val;
      } else if (
        tags[tagIdx].includes("ZUUU_DEP") ||
        tags[tagIdx].includes("ZUTF_DEP")
      ) {
        valDep += val;
      } else if (tags[tagIdx].includes("ARR_UBKER")) {
        valPass += val;
      } else if (
        tags[tagIdx].includes("ZUMY_DEP_BOKIR") ||
        tags[tagIdx].includes("ZUMY_DEP_SAGPI") ||
        tags[tagIdx].includes("ZUMY_DEP_UBRAB")
      ) {
        valDepMainMY += val;
      } else if (tags[tagIdx].includes("ZUMY_DEP_JTG")) {
        valDepMiscMY += val;
      } else if (tags[tagIdx].includes("ZUMY_ARR")) {
        valArrMY += val;
      }
    });
    let isolate = 0;
    // if (valArr > 6) {
    //   if (opMode == "SSWJ" && (valDep > 20 || valArr > 12)) {
    //     isolate = 1; // 双流向南，天府向南，丁树有活动
    //   } else if (opMode == "SS" && (valDep > 22 || valArr > 12)) {
    //     isolate = 1; // 双流向南，天府向南，丁树无活动
    //   } else if (opMode.includes("WJ") && (valDep > 21 || valArr > 12)) {
    //     isolate = 1; // 其他运行模式，丁树有活动
    //   } else if (valDep > 24 || valArr > 12) {
    //     isolate = 1; // 其他运行模式，丁树无活动
    //   }
    // }
    taggedData.push({
      day,
      valArr,
      valDep,
      valAll,
      isolate,
      opMode,
      details,
      valDepMainMY,
      valDepMiscMY,
      valArrMY,
      valPass,
    });
  }
  return taggedData;
}
